package oop.core.med;

import oop.core.entity.Avatar;
import oop.core.item.*;
import oop.core.visitors.UseVisitor;

public class InventoryManagementMediator implements Pausable{

	private Avatar avatar;
	private ItemPlacementMediator itemPlacementMediator;
	private boolean paused;
	
	public InventoryManagementMediator(Avatar avatar, ItemPlacementMediator ipm){
		this.avatar = avatar;
		this.itemPlacementMediator = ipm;
		paused = false;
	}
	
	public void useItem(int i)
	{
		if( paused )
		{
			return;
		}
		
		TakeableItem itemCheck = avatar.getItem(i);
		if(itemCheck != null)
		{
			itemCheck.accept(new UseVisitor(avatar));
		}
	}
	
	public void dropItem(int i)
	{
		if( paused )
		{
			return;
		}
		
		TakeableItem itemcheck = avatar.getItem(i);
		if(itemcheck != null)
		{
			itemPlacementMediator.dropItem(i);
		}	
	}

	public void pause() {
		paused = true;		
	}

	public void toggle() {
		paused = !paused;
	}

	public void unpause() {
		paused = false;
	}
}


